var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = (function () {
    function e(e, t) {
        (this.saveKey = ""), (this.type = typeof t), (this.saveKey = e), (this.localValue = t), this.loadFormStorage();
    }
    return (
        Object.defineProperty(e.prototype, "value", {
            get: function () {
                return this.localValue;
            },
            set: function (e) {
                (this.localValue = e), this.saveToStorage();
            },
            enumerable: !1,
            configurable: !0
        }),
        (e.resetAllHardData = function () {
            cc.sys.localStorage.clear();
        }),
        (e.prototype.loadFormStorage = function () {
            var e = cc.sys.localStorage.getItem(this.saveKey),
                t = this.localValue;
            switch (this.type) {
                case "boolean":
                    e && (t = "true" == e);
                    break;
                case "number":
                    e && (t = Number(e));
                    break;
                case "string":
                    e && (t = e);
                    break;
                case "object":
                    e && (t = JSON.parse(e));
                    break;
                default:
                    return void cc.error("HardData 类型错误");
            }
            this.localValue = t;
        }),
        (e.prototype.saveToStorage = function () {
            var e = null;
            switch (this.type) {
                case "boolean":
                    e = this.localValue ? "true" : "false";
                    break;
                case "number":
                    e = this.localValue.toString();
                    break;
                case "string":
                    e = this.localValue;
                    break;
                case "object":
                    e = JSON.stringify(this.localValue);
                    break;
                default:
                    return void cc.error("HardData 类型错误");
            }
            cc.sys.localStorage.setItem(this.saveKey, e);
        }),
        e
    );
})();
o.default = n;
